home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14008 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  76 lines

  1. Path: news.tu-ilmenau.de!usenet
  2. From: Lars Krueger <ai108@rz.tu-ilmenau.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Is WATCOM 10.5 a broken compiler or am I stupid?
  5. Date: Thu, 28 Mar 1996 13:46:33 +0100
  6. Organization: Technische Universitaet Ilmenau
  7. Message-ID: <315A8A29.613B4EBA@rz.tu-ilmenau.de>
  8. NNTP-Posting-Host: scenic-03.rz.tu-ilmenau.de
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.13 i586)
  13.  
  14. Hi.
  15.  
  16. Yesterday I came across a strange error caused by following code:
  17.  
  18. typedef struct cstringTEMP
  19. {
  20.  char len;
  21.  char data[255];
  22.  public:
  23.  cstringTEMP & operator=(char *);
  24. } cstring;
  25.  
  26. char pchar2cstring(cstring &s, char *c)
  27. // Returns 1 for "c to long". 
  28. // Returns 0 for success.
  29. {
  30.  unsigned l=strlen(c);
  31.  if( l>255)
  32.   return 1;
  33.  s.len=(char )l;
  34.  memcpy(s.data,c,l);
  35.  return 0;
  36. }
  37.  
  38. cstring & cstring::operator=(char *s)
  39. {
  40.  if( pchar2cstring(*this,s))
  41.   len=0;
  42.  return *this;
  43. }
  44.  
  45.  
  46.  
  47.  
  48. AND THIS IS THE CODE I TRIED TO USE:
  49.  
  50.  cstring cs="test";
  51.  
  52.  
  53. IT GAVE THIS ERROR-MESSAGE: (I CUT OUT THE LINE NUMBERS AND THE FILENAME
  54. TO SAVE SPACE.)
  55. Error! E400: (col 13) cannot convert right expression for initialization 
  56. Note! N643: (col 13) cannot convert argument 1 defined in: 
  57. Note! N630: (col 13) source conversion type is "char *" 
  58. Note! N631: (col 13) target conversion type is "cstringTEMP const &" 
  59.  
  60. CHANGING THE LINE ABOVE TO:
  61.  
  62. cstring cs;
  63. cs="test";
  64.  
  65.  
  66. AND THE ERROR WAS NOT LONGER THERE.
  67.  
  68. And now are my questions
  69. 1.) Is this all my fault or a bug in the WATCOM C++ compiler.
  70. 2.) If it is my fault how do I have to change the declaration.
  71.  
  72.  
  73. Thanks in advance
  74.  
  75. Lars
  76.